# -*- coding:UTF-8 -*- ＃
#!/usr/bin/python
'''
Created on 2013-5-22

@author: Administrator
'''
import os

dirs = set()
def findFile(folder,isFile,match):
    "遍历文件夹"
    for item in os.listdir(folder):
        path = os.path.join(folder,item)
        if os.path.isdir(path) :
            if (not isFile) and item == match:
                dirs.add(path)
            findFile(path,isFile,match)
        else :
            if isFile and item == match:
                dirs.add(path)
    return dirs

def copyFiles(sourceDir, targetDir): 
    for file in os.listdir(sourceDir): 
        sourceFile = os.path.join(sourceDir, file) 
        targetFile = os.path.join(targetDir, file) 
        print(sourceFile + '复制到==>' + targetFile)
        if os.path.isfile(sourceFile): 
            open(targetFile, "wb").write(open(sourceFile, "rb").read())

if __name__ == '__main__':
    dirs = findFile('/home/hightech/image/',False,'failed')
    for path in dirs:
        targetDir,tail = os.path.split(path);
        copyFiles(path, targetDir)